import "reflect-metadata";
import config from "@/config/config.default";
import { AppFactory } from "@/common/core";
import { middleware } from "./middleware";
import * as entitys from "./modules/entitys";
import * as modules from "./modules/index";

async function bootstrap() {
  await AppFactory.middleware(middleware);
  // console.log("config", config);
  await AppFactory.typeorm({ ...config.orm, entities: Object.values(entitys) });

  // 路径前缀：如：http://www.test.com/api/v1/user
  await AppFactory.setGlobalPrefix("/api");

  await AppFactory.module(Object.values(modules));

  await AppFactory.listen(config.koa.port, (v: any) => {
    console.log(`服务器启动成功${config.koa.host}:${config.koa.port}`);
  });
}

void bootstrap();
